home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DTP / DTP_TEX / H067.ZIP / JIS2MF.C < prev    next >
C/C++ Source or Header  |  1991-04-14  |  38KB  |  997 lines

  1. /* -mt -f -A -K -G -O -w */
  2. /* Compile with Turbo-C 2.0 */
  3. /*
  4.   This program generates METAFONT code from a Bitmaps file JIS24
  5.  
  6.   Author: Francois Jalbert
  7.               '
  8.   Date: November 1990
  9.  
  10.   Version: 1.0
  11.  
  12.   Date: April 1991
  13.  
  14.   Version: 2.00
  15.  
  16.   Modifications: - Added four kanjis.
  17.                  - Fixed incorrect VGA resolution.
  18.                  - Command line parameter now supported.
  19.                  - Added automatic mode.
  20.                  - Added batch mode.
  21.                  - Updated and improved run-time messages.
  22.                  - Long triangles added by Mr. Masatoshi Watanabe. Fantastic!
  23.                  - Fixed and proportional parameters added.
  24.                  - Standard and dictionary parameters added.
  25.                  - JIS24 now accessed through low-level I/O channel for speed.
  26.  
  27.   Error Levels: 0 - Normal termination.
  28.                 1 - Error.
  29.                 2 - All fonts generated (batch).
  30. */
  31.  
  32. #include <stdio.h>
  33. #include <string.h>
  34. #include <ctype.h>
  35. #ifdef __TURBOC__
  36. #include <process.h>
  37. #endif
  38.  
  39. #define True  1
  40. #define False 0
  41. /* Number of Bitmaps in JIS24 */
  42. #define BitmapMax 7806
  43. /* Size of each square Bitmap */
  44. #define SizeMax  24
  45. #define SizeMax1 25
  46. /* DOS file name length */
  47. #define FileNameDOS  250 /* includes path */
  48. #define TotalNameDOS 254
  49. /* DOS Record Size */
  50. #define RecSize 72 /* SizeMax*SizeMax/8 */
  51. /* Parameter flag */
  52. #define Flag1 '/' /* DOS style */
  53. #define Flag2 '-' /* UNIX style */
  54. /* Parameter keywords */
  55. #define ParamMax 20
  56. char FixedX1[]="FIXEDWIDTH";
  57. char FixedX2[]="FIXEDX";
  58. char FixedX3[]="NOPROPORTIONALWIDTH";
  59. char FixedX4[]="NOPROPORTIONALX";
  60. char NoFixedX1[]="NOFIXEDWIDTH";
  61. char NoFixedX2[]="NOFIXEDX";
  62. char NoFixedX3[]="PROPORTIONALWIDTH";
  63. char NoFixedX4[]="PROPORTIONALX";
  64. char FixedY1[]="FIXEDHEIGHT";
  65. char FixedY2[]="FIXEDY";
  66. char FixedY3[]="NOPROPORTIONALHEIGHT";
  67. char FixedY4[]="NOPROPORTIONALY";
  68. char NoFixedY1[]="NOFIXEDHEIGHT";
  69. char NoFixedY2[]="NOFIXEDY";
  70. char NoFixedY3[]="PROPORTIONALHEIGHT";
  71. char NoFixedY4[]="PROPORTIONALY";
  72. char Standard1[]="STANDARD";
  73. char NoStandard1[]="DICTIONARY";
  74. char Batch1[]="BATCH";
  75. /* Answer maximum length */
  76. #define AnswerMax 254
  77.  
  78. typedef char FileNameType[FileNameDOS+1];
  79. typedef char TotalNameType[TotalNameDOS+1];
  80. typedef char ParamType[ParamMax+1];
  81. typedef char AnswerType[AnswerMax+1];
  82. /* Buffer for the Bitmap Data */
  83. struct ColumnType {
  84.   unsigned char Data1,Data2,Data3;
  85. };
  86. typedef struct ColumnType BufferType[SizeMax]; /* start at 0 because of fread */
  87. /* The Bitmap array is defined larger to simplify the forthcoming code */
  88. typedef int BitmapType[SizeMax1+1][SizeMax1+1];
  89. struct BitmapsType {
  90.   BitmapType Bitmap;
  91.   int XMin,XMax,YMin,YMax;
  92. };
  93. /* Run time parameters */
  94. struct RunTimeType {
  95.   FileNameType FileName;
  96.   /* Batch mode */
  97.   int Batch;
  98.   /* Automatic mode for JemTeX fonts only */
  99.   int Automatic;
  100.   /* Fixed or proportional fonts */
  101.   int FixedX,FixedY;
  102.   /* Standard or dictionary fonts */
  103.   int Standard;
  104. };
  105.  
  106. void Delete(char *String, int Length)
  107. /* Delete the first Length characters of String */
  108. {
  109.   int Index;
  110.  
  111.   Index=0;
  112.   do String[Index]=String[Index+Length];
  113.   while (String[++Index]!='\0');
  114. }
  115.  
  116. /*------------------------------- GetParameters -----------------------------*/
  117.  
  118. void SimpleQuery(char Title[], char ChoiceA[], char ChoiceB[], int *Answer)
  119. {
  120.   char JChar[2];
  121.   int Valid;
  122.  
  123.   do {
  124.     Valid=True;
  125.     printf("%s:\n",Title);
  126.     printf("   a)  %s\n",ChoiceA);
  127.     printf("   b)  %s\n",ChoiceB);
  128.     printf("Your choice? ");
  129.     if (ferror(stdout)) exit(1);
  130.     if (gets(JChar)==NULL) exit(1);
  131.     if (strlen(JChar)>1) exit(1);
  132.     JChar[0]=toupper(JChar[0]);
  133.     if (JChar[0]=='A') *Answer=True;
  134.     else
  135.       if (JChar[0]=='B') *Answer=False;
  136.       else { 
  137.         Valid=False; 
  138.         if (putchar('\7')==EOF) exit(1); 
  139.     }
  140.   } while (!Valid);
  141.   printf("\n");
  142.   if (ferror(stdout)) exit(1);
  143. }
  144.  
  145. void GetMode(struct RunTimeType *RunTime)
  146. /* Determines if the desired font is a JemTeX font */
  147. {
  148.   RunTime->Automatic=False;
  149.   if (toupper(RunTime->FileName[0])=='K')
  150.   if (toupper(RunTime->FileName[1])=='A')
  151.   if (toupper(RunTime->FileName[2])=='N')
  152.   if (toupper(RunTime->FileName[3])=='J')
  153.   if (toupper(RunTime->FileName[4])=='I')
  154.   if(('A'<=toupper(RunTime->FileName[5]))&&(toupper(RunTime->FileName[5])<='H'))
  155.   if(('A'<=toupper(RunTime->FileName[6]))&&(toupper(RunTime->FileName[6])<='H'))
  156.   if (strlen(RunTime->FileName)==7)
  157.   if (toupper(RunTime->FileName[5])<='G') RunTime->Automatic=True;
  158.   else
  159.   if (toupper(RunTime->FileName[6])<='E') RunTime->Automatic=True;
  160. }
  161.  
  162. void EchoParameters(struct RunTimeType *RunTime)
  163. /* Echoes the current parameters */
  164. {
  165.   printf("Font=%s",RunTime->FileName);
  166.   if (RunTime->FixedX) printf("  Fixed Width");
  167.   else printf("  Prop. Width");
  168.   if (RunTime->FixedY) printf("  Fixed Height");
  169.   else printf("  Prop. Height");
  170.   if (RunTime->Standard) printf("  Standard");
  171.   else printf("  Dictionary");
  172.   if (RunTime->Automatic) printf("  Automatic");
  173.   else printf("  Manual");
  174.   if (RunTime->Batch) printf("  Batch");
  175.   printf(".\n");
  176.   if (ferror(stdout)) exit(1);
  177. }
  178.  
  179. void Manual(struct RunTimeType *RunTime)
  180. /* Get parameters from user */
  181. {
  182.   printf("METAFONT file name? ");
  183.   if (ferror(stdout)) exit(1);
  184.   if (gets(RunTime->FileName)==NULL) exit(1);
  185.   if (strlen(RunTime->FileName)>FileNameDOS) {
  186.     /* File name too long */
  187.     printf("\7File name too long: %s...",RunTime->FileName);
  188.     exit(1);
  189.   }
  190.   printf("\n");
  191.   if (ferror(stdout)) exit(1);
  192.   SimpleQuery("Fixed or proportional font width","Fixed","Proportional",
  193.               &RunTime->FixedX);
  194.   SimpleQuery("Fixed or proportional font height","Fixed","Proportional",
  195.               &RunTime->FixedY);
  196.   SimpleQuery("Standard or dictionary font","Standard","Dictionary",
  197.               &RunTime->Standard);
  198.   /* Batch mode intrinsically isn't manual */
  199.   RunTime->Batch=False;
  200. }
  201.  
  202. void FindBefore(FileNameType FileName)
  203. /* No check for before kanjiaa */
  204. {
  205.   if (FileName[6]=='a') {
  206.     FileName[6]='h';
  207.     FileName[5]--;
  208.   }
  209.   else
  210.     FileName[6]--;
  211. }
  212.  
  213. void FindAfter(FileNameType FileName)
  214. /* No check for above kanjihe */
  215. {
  216.   if (FileName[6]=='h') {
  217.     FileName[6]='a';
  218.     FileName[5]++;
  219.   }
  220.   else
  221.     FileName[6]++;
  222. }
  223.  
  224. void ScanMF(FileNameType FileName)
  225. /* Scans backwards for the last JemTeX font generated */
  226. /* Looks first for a .TFM and then for an .MF */
  227. /* If no more fonts to generate, stops with error level 2 */
  228. {
  229.   FILE *TestFile;
  230.   TotalNameType TotalName;
  231.   int Found;
  232.  
  233.   strcpy(FileName,"kanjihf");
  234.   do {
  235.     FindBefore(FileName);
  236.     strcpy(TotalName,FileName);
  237.     strcat(TotalName,".tfm");
  238.     TestFile=fopen(TotalName,"r");
  239.     Found=(TestFile!=NULL);
  240.     if (!Found) {
  241.       strcpy(TotalName,FileName);
  242.       strcat(TotalName,".mf");
  243.       TestFile=fopen(TotalName,"r");
  244.       Found=(TestFile!=NULL);
  245.     }
  246.   } while (!Found && strcmp(FileName,"kanjiaa"));
  247.   if (Found) {
  248.     if (fclose(TestFile)==EOF) exit(1);
  249.     if (strcmp(FileName,"kanjihe")) FindAfter(FileName);
  250.     else {
  251.       printf("\7All JemTeX fonts generated!\n");
  252.       exit(2);
  253.     }
  254.   }
  255. }
  256.  
  257. void Automate(struct RunTimeType *RunTime, int argc, char *argv[])
  258. /* Get parameters from command line */
  259. /* Finds the next font to be generated if in batch mode */
  260. {
  261.   int ParamIndex,ParamLength,Index;
  262.   ParamType Param;
  263.  
  264.   /* Defaults */
  265.   strcpy(RunTime->FileName,"kanjiaa");
  266.   RunTime->FixedX=False;
  267.   RunTime->FixedY=False;
  268.   RunTime->Standard=True;
  269.   RunTime->Batch=False;
  270.   /* Scan command line parameters */
  271.   /* 0th is program's name, last is NULL */
  272.   for (ParamIndex=1 ; ParamIndex<argc ; ParamIndex++) {
  273.     ParamLength=strlen(argv[ParamIndex]);
  274.     if (ParamLength>ParamMax) {
  275.       /* Keyword too long */
  276.       printf("\7Invalid command line parameter: %s...",argv[ParamIndex]);
  277.       exit(1);
  278.     }
  279.     strcpy(Param,argv[ParamIndex]);
  280.     if ((Param[0]==Flag1) || (Param[0]==Flag2)) {
  281.       /* Not a font name */
  282.       /* Delete 1 char at the 1st position */
  283.       Delete(Param,1);
  284.       /* Convert to upper case */
  285.       for (Index=0 ; Index<ParamLength ; Index++)
  286.         Param[Index]=toupper(Param[Index]);
  287.       /* Scan known keywords */
  288.       if ((!strcmp(Param,FixedX1)) || (!strcmp(Param,FixedX2)) || 
  289.           (!strcmp(Param,FixedX3)) || (!strcmp(Param,FixedX4))) 
  290.         RunTime->FixedX=True;
  291.       else
  292.       if ((!strcmp(Param,NoFixedX1)) || (!strcmp(Param,NoFixedX2)) ||
  293.           (!strcmp(Param,NoFixedX3)) || (!strcmp(Param,NoFixedX4))) 
  294.         RunTime->FixedX=False;
  295.       else
  296.       if ((!strcmp(Param,FixedY1)) || (!strcmp(Param,FixedY2)) || 
  297.           (!strcmp(Param,FixedY3)) || (!strcmp(Param,FixedY4))) 
  298.         RunTime->FixedY=True;
  299.       else
  300.       if ((!strcmp(Param,NoFixedY1)) || (!strcmp(Param,NoFixedY2)) || 
  301.           (!strcmp(Param,NoFixedY3)) || (!strcmp(Param,NoFixedY4))) 
  302.         RunTime->FixedY=False;
  303.       else
  304.       if (!strcmp(Param,Standard1)) 
  305.         RunTime->Standard=True;
  306.       else
  307.       if (!strcmp(Param,NoStandard1)) 
  308.         RunTime->Standard=False;
  309.       else
  310.       if (!strcmp(Param,Batch1)) 
  311.         RunTime->Batch=True;
  312.       else {
  313.         /* Unknown keyword */
  314.         printf("\7Invalid command line parameter: %s...\n",Param);
  315.         exit(1);
  316.       }
  317.     }
  318.     else {
  319.       /* Must be a font name */
  320.       if (ParamLength>FileNameDOS) {
  321.         /* File name too long */
  322.         printf("\7File name too long: %s...\n",Param);
  323.         exit(1);
  324.       }
  325.       strcpy(RunTime->FileName,Param);
  326.     }
  327.   }
  328.   if (RunTime->Batch) ScanMF(RunTime->FileName);
  329. }
  330.  
  331. void GetParameters(struct RunTimeType *RunTime, int argc, char *argv[])
  332. /* Get parameters from user or command line */
  333. {
  334.   /* 0th is program's name, last is NULL */
  335.   if (argc==1) Manual(RunTime);
  336.   else Automate(RunTime,argc,argv);
  337.   GetMode(RunTime);
  338.   EchoParameters(RunTime);
  339.   printf("\n");
  340.   if (ferror(stdout)) exit(1);
  341. }
  342.  
  343. /*---------------------------------- Output ---------------------------------*/
  344.  
  345. void BeginOut(FILE *OutFile, struct RunTimeType *RunTime)
  346. /* Writes initial METAFONT header */
  347. /* Co-author is Mr. Masatoshi Watanabe */
  348. {
  349.   fprintf(OutFile,"%%JIS2MF Version 2.00 of 14 April 1991.\n");
  350.   fprintf(OutFile,"\n");
  351.   fprintf(OutFile,"%% Font=%s\n",RunTime->FileName);
  352.   if (RunTime->FixedX) fprintf(OutFile,"%% Fixed Width\n");
  353.   else fprintf(OutFile,"%% Proportional Width\n");
  354.   if (RunTime->FixedY) fprintf(OutFile,"%% Fixed Height\n");
  355.   else fprintf(OutFile,"%% Proportional Height\n");
  356.   if (RunTime->Standard) fprintf(OutFile,"%% Standard Positioning\n");
  357.   else fprintf(OutFile,"%% Dictionary Positioning\n");
  358.   fprintf(OutFile,"\n");
  359.   fprintf(OutFile,"tracingstats:=1;\n");
  360.   fprintf(OutFile,"screen_cols:=640; %%VGA\n");
  361.   fprintf(OutFile,"screen_rows:=480; %%VGA\n");
  362.   fprintf(OutFile,"font_size 10pt#;\n");
  363.   if (RunTime->Standard) {
  364.     fprintf(OutFile,"u#:=12.7/36pt#;\n");
  365.     fprintf(OutFile,"body_height#:=23.25u#;\n");
  366.     fprintf(OutFile,"desc_depth#:=4.75u#;\n");
  367.   }
  368.   else {
  369.     fprintf(OutFile,"u#:=13/36pt#;\n");
  370.     fprintf(OutFile,"body_height#:=21u#;\n");
  371.     fprintf(OutFile,"desc_depth#:=7u#;\n");
  372.   }
  373.   fprintf(OutFile,"\n");
  374.   fprintf(OutFile,"letter_fit#:=0pt#;\n");
  375.   fprintf(OutFile,"asc_height#:=0pt#;\n");
  376.   fprintf(OutFile,"cap_height#:=0pt#;\n");
  377.   fprintf(OutFile,"fig_height#:=0pt#;\n");
  378.   fprintf(OutFile,"x_height#:=0pt#;\n");
  379.   fprintf(OutFile,"math_axis#:=0pt#;\n");
  380.   fprintf(OutFile,"bar_height#:=0pt#;\n");
  381.   fprintf(OutFile,"comma_depth#:=0pt#;\n");
  382.   fprintf(OutFile,"crisp#:=0pt#;\n");
  383.   fprintf(OutFile,"tiny#:=0pt#;\n");
  384.   fprintf(OutFile,"fine#:=0pt#;\n");
  385.   fprintf(OutFile,"thin_join#:=0pt#;\n");
  386.   fprintf(OutFile,"hair#:=1pt#;\n");
  387.   fprintf(OutFile,"stem#:=1pt#;\n");
  388.   fprintf(OutFile,"curve#:=1pt#;\n");
  389.   fprintf(OutFile,"flare#:=1pt#;\n");
  390.   fprintf(OutFile,"dot_size#:=0pt#;\n");
  391.   fprintf(OutFile,"cap_hair#:=1pt#;\n");
  392.   fprintf(OutFile,"cap_stem#:=1pt#;\n");
  393.   fprintf(OutFile,"cap_curve#:=1pt#;\n");
  394.   fprintf(OutFile,"rule_thickness#:=0pt#;\n");
  395.   fprintf(OutFile,"vair#:=0pt#;\n");
  396.   fprintf(OutFile,"notch_cut#:=0pt#;\n");
  397.   fprintf(OutFile,"bar#:=1pt#;\n");
  398.   fprintf(OutFile,"slab#:=1pt#;\n");
  399.   fprintf(OutFile,"cap_bar#:=1pt#;\n");
  400.   fprintf(OutFile,"cap_band#:=1pt#;\n");
  401.   fprintf(OutFile,"cap_notch_cut#:=0pt#;\n");
  402.   fprintf(OutFile,"serif_drop#:=0pt#;\n");
  403.   fprintf(OutFile,"stem_corr#:=0pt#;\n");
  404.   fprintf(OutFile,"vair_corr#:=0pt#;\n");
  405.   fprintf(OutFile,"o#:=0pt#;\n");
  406.   fprintf(OutFile,"apex_o#:=0pt#;\n");
  407.   fprintf(OutFile,"hefty:=true;\n");
  408.   fprintf(OutFile,"serifs:=true;\n");
  409.   fprintf(OutFile,"monospace:=false;\n");
  410.   fprintf(OutFile,"math_fitting:=false;\n");
  411.   fprintf(OutFile,"\n");
  412.   fprintf(OutFile,"mode_setup;\n");
  413.   fprintf(OutFile,"font_setup;\n");
  414.   fprintf(OutFile,"\n");
  415.   fprintf(OutFile,"pair z;\n");
  416.   fprintf(OutFile,"\n");
  417.   fprintf(OutFile,"def s(expr col,row)= %%square\n");
  418.   fprintf(OutFile," z:=((col*u),(row*u));\n");
  419.   fprintf(OutFile," fill unitsquare scaled u shifted z;\n");
  420.   fprintf(OutFile,"enddef;\n");
  421.   fprintf(OutFile,"def sul(expr col,row)= %%upper left square\n");
  422.   fprintf(OutFile," z:=((col*u),(row*u)+.5u);\n");
  423.   fprintf(OutFile," fill unitsquare scaled .5u shifted z;\n");
  424.   fprintf(OutFile,"enddef;\n");
  425.   fprintf(OutFile,"def sur(expr col,row)= %%upper right square\n");
  426.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+.5u);\n");
  427.   fprintf(OutFile," fill unitsquare scaled .5u shifted z;\n");
  428.   fprintf(OutFile,"enddef;\n");
  429.   fprintf(OutFile,"def sbr(expr col,row)= %%bottom right square\n");
  430.   fprintf(OutFile," z:=((col*u)+.5u,(row*u));\n");
  431.   fprintf(OutFile," fill unitsquare scaled .5u shifted z;\n");
  432.   fprintf(OutFile,"enddef;\n");
  433.   fprintf(OutFile,"def sbl(expr col,row)= %%bottom left square\n");
  434.   fprintf(OutFile," z:=((col*u),(row*u));\n");
  435.   fprintf(OutFile," fill unitsquare scaled .5u shifted z;\n");
  436.   fprintf(OutFile,"enddef;\n");
  437.   fprintf(OutFile,"\n");
  438.   fprintf(OutFile,"def c(expr col,row)= %%circle\n");
  439.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+.5u);\n");
  440.   fprintf(OutFile," fill fullcircle scaled u shifted z;\n");
  441.   fprintf(OutFile,"enddef;\n");
  442.   fprintf(OutFile,"def cul(expr col,row)= %%upper left circle\n");
  443.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+.5u);\n");
  444.   fprintf(OutFile," fill z--quartercircle rotated 90 scaled u shifted z--cycle;\n");
  445.   fprintf(OutFile,"enddef;\n");
  446.   fprintf(OutFile,"def cur(expr col,row)= %%upper right circle\n");
  447.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+.5u);\n");
  448.   fprintf(OutFile," fill z--quartercircle scaled u shifted z--cycle;\n");
  449.   fprintf(OutFile,"enddef;\n");
  450.   fprintf(OutFile,"def cbr(expr col,row)= %%bottom right circle\n");
  451.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+.5u);\n");
  452.   fprintf(OutFile," fill z--quartercircle rotated 270 scaled u shifted z--cycle;\n");
  453.   fprintf(OutFile,"enddef;\n");
  454.   fprintf(OutFile,"def cbl(expr col,row)= %%bottom left circle\n");
  455.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+.5u);\n");
  456.   fprintf(OutFile," fill z--quartercircle rotated 180 scaled u shifted z--cycle;\n");
  457.   fprintf(OutFile,"enddef;\n");
  458.   fprintf(OutFile,"\n");
  459.   fprintf(OutFile,"def tul(expr col,row)= %%upper left triangle\n");
  460.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+.5u);\n");
  461.   fprintf(OutFile," fill z--z+(0,.5u)--z-(.5u,0)--cycle;\n");
  462.   fprintf(OutFile,"enddef;\n");
  463.   fprintf(OutFile,"def tur(expr col,row)= %%upper right triangle\n");
  464.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+.5u);\n");
  465.   fprintf(OutFile," fill z--z+(0,.5u)--z+(.5u,0)--cycle;\n");
  466.   fprintf(OutFile,"enddef;\n");
  467.   fprintf(OutFile,"def tbr(expr col,row)= %%bottom right triangle\n");
  468.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+.5u);\n");
  469.   fprintf(OutFile," fill z--z-(0,.5u)--z+(.5u,0)--cycle;\n");
  470.   fprintf(OutFile,"enddef;\n");
  471.   fprintf(OutFile,"def tbl(expr col,row)= %%bottom left triangle\n");
  472.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+.5u);\n");
  473.   fprintf(OutFile," fill z--z-(0,.5u)--z-(.5u,0)--cycle;\n");
  474.   fprintf(OutFile,"enddef;\n");
  475.   fprintf(OutFile,"\n");
  476.   fprintf(OutFile,"def rul(expr col,row)= %%upper left reverse triangle\n");
  477.   fprintf(OutFile," z:=((col*u),(row*u)+u);\n");
  478.   fprintf(OutFile," fill z--z-(0,.5u)--z+(.5u,0)--cycle;\n");
  479.   fprintf(OutFile,"enddef;\n");
  480.   fprintf(OutFile,"def rur(expr col,row)= %%upper right reverse triangle\n");
  481.   fprintf(OutFile," z:=((col*u)+u,(row*u)+u);\n");
  482.   fprintf(OutFile," fill z--z-(0,.5u)--z-(.5u,0)--cycle;\n");
  483.   fprintf(OutFile,"enddef;\n");
  484.   fprintf(OutFile,"def rbr(expr col,row)= %%bottom right reverse triangle\n");
  485.   fprintf(OutFile," z:=((col*u)+u,(row*u));\n");
  486.   fprintf(OutFile," fill z--z+(0,.5u)--z-(.5u,0)--cycle;\n");
  487.   fprintf(OutFile,"enddef;\n");
  488.   fprintf(OutFile,"def rbl(expr col,row)= %%bottom left reverse triangle\n");
  489.   fprintf(OutFile," z:=((col*u),(row*u));\n");
  490.   fprintf(OutFile," fill z--z+(0,.5u)--z+(.5u,0)--cycle;\n");
  491.   fprintf(OutFile,"enddef;\n");
  492.   fprintf(OutFile,"\n");
  493.   fprintf(OutFile,"def tuul(expr col,row)= %%upper left long triangle\n");
  494.   fprintf(OutFile," z:=((col*u)+u,(row*u)+.5u);\n");
  495.   fprintf(OutFile," fill z--z+(0,.5u)--z-(u,0)--cycle;\n");
  496.   fprintf(OutFile,"enddef;\n");
  497.   fprintf(OutFile,"def tull(expr col,row)= %%upper left long triangle\n");
  498.   fprintf(OutFile," z:=((col*u)+.5u,(row*u));\n");
  499.   fprintf(OutFile," fill z--z+(0,u)--z-(.5u,0)--cycle;\n");
  500.   fprintf(OutFile,"enddef;\n");
  501.   fprintf(OutFile,"def tuur(expr col,row)= %%upper right long triangle\n");
  502.   fprintf(OutFile," z:=((col*u),(row*u)+.5u);\n");
  503.   fprintf(OutFile," fill z--z+(0,.5u)--z+(u,0)--cycle;\n");
  504.   fprintf(OutFile,"enddef;\n");
  505.   fprintf(OutFile,"def turr(expr col,row)= %%upper right long triangle\n");
  506.   fprintf(OutFile," z:=((col*u)+.5u,(row*u));\n");
  507.   fprintf(OutFile," fill z--z+(0,u)--z+(.5u,0)--cycle;\n");
  508.   fprintf(OutFile,"enddef;\n");
  509.   fprintf(OutFile,"def tbbr(expr col,row)= %%bottom right long triangle\n");
  510.   fprintf(OutFile," z:=((col*u),(row*u)+.5u);\n");
  511.   fprintf(OutFile," fill z--z-(0,.5u)--z+(u,0)--cycle;\n");
  512.   fprintf(OutFile,"enddef;\n");
  513.   fprintf(OutFile,"def tbrr(expr col,row)= %%bottom right long triangle\n");
  514.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+u);\n");
  515.   fprintf(OutFile," fill z--z-(0,u)--z+(.5u,0)--cycle;\n");
  516.   fprintf(OutFile,"enddef;\n");
  517.   fprintf(OutFile,"def tbbl(expr col,row)= %%bottom left long triangle\n");
  518.   fprintf(OutFile," z:=((col*u)+u,(row*u)+.5u);\n");
  519.   fprintf(OutFile," fill z--z-(0,.5u)--z-(u,0)--cycle;\n");
  520.   fprintf(OutFile,"enddef;\n");
  521.   fprintf(OutFile,"def tbll(expr col,row)= %%bottom left long triangle\n");
  522.   fprintf(OutFile," z:=((col*u)+.5u,(row*u)+u);\n");
  523.   fprintf(OutFile," fill z--z-(0,u)--z-(.5u,0)--cycle;\n");
  524.   fprintf(OutFile,"enddef;\n");
  525.   fprintf(OutFile,"\n");
  526.   fprintf(OutFile,"def ruul(expr col,row)= %%upper left reverse long triangle\n");
  527.   fprintf(OutFile," z:=((col*u),(row*u)+u);\n");
  528.   fprintf(OutFile," fill z--z-(0,u)--z+(.5u,0)--cycle;\n");
  529.   fprintf(OutFile,"enddef;\n");
  530.   fprintf(OutFile,"def rull(expr col,row)= %%upper left reverse long triangle\n");
  531.   fprintf(OutFile," z:=((col*u),(row*u)+u);\n");
  532.   fprintf(OutFile," fill z--z-(0,.5u)--z+(u,0)--cycle;\n");
  533.   fprintf(OutFile,"enddef;\n");
  534.   fprintf(OutFile,"def ruur(expr col,row)= %%upper right reverse long triangle\n");
  535.   fprintf(OutFile," z:=((col*u)+u,(row*u)+u);\n");
  536.   fprintf(OutFile," fill z--z-(0,u)--z-(.5u,0)--cycle;\n");
  537.   fprintf(OutFile,"enddef;\n");
  538.   fprintf(OutFile,"def rurr(expr col,row)= %%upper right reverse long triangle\n");
  539.   fprintf(OutFile," z:=((col*u)+u,(row*u)+u);\n");
  540.   fprintf(OutFile," fill z--z-(0,.5u)--z-(u,0)--cycle;\n");
  541.   fprintf(OutFile,"enddef;\n");
  542.   fprintf(OutFile,"def rbbr(expr col,row)= %%bottom right reverse long triangle\n");
  543.   fprintf(OutFile," z:=((col*u)+u,(row*u));\n");
  544.   fprintf(OutFile," fill z--z+(0,u)--z-(.5u,0)--cycle;\n");
  545.   fprintf(OutFile,"enddef;\n");
  546.   fprintf(OutFile,"def rbrr(expr col,row)= %%bottom right reverse long triangle\n");
  547.   fprintf(OutFile," z:=((col*u)+u,(row*u));\n");
  548.   fprintf(OutFile," fill z--z+(0,.5u)--z-(u,0)--cycle;\n");
  549.   fprintf(OutFile,"enddef;\n");
  550.   fprintf(OutFile,"def rbbl(expr col,row)= %%bottom left reverse long triangle\n");
  551.   fprintf(OutFile," z:=((col*u),(row*u));\n");
  552.   fprintf(OutFile," fill z--z+(0,u)--z+(.5u,0)--cycle;\n");
  553.   fprintf(OutFile,"enddef;\n");
  554.   fprintf(OutFile,"def rbll(expr col,row)= %%bottom left reverse long triangle\n");
  555.   fprintf(OutFile," z:=((col*u),(row*u));\n");
  556.   fprintf(OutFile," fill z--z+(0,.5u)--z+(u,0)--cycle;\n");
  557.   fprintf(OutFile,"enddef;\n");
  558.   fprintf(OutFile,"\n");
  559.   if (ferror(OutFile)) exit(1);
  560. }
  561.  
  562. void ActiveBitmap(FILE *OutFile, BitmapType Bitmap, int X, int Y, int XX, 
  563.                   float YY)
  564. /* Writes METAFONT code for an active cell */
  565. /* Co-author is Mr. Masatoshi Watanabe */
  566. {
  567.   int SquareUR,SquareUL,SquareBR,SquareBL;
  568.   int CircleUR,CircleUL,CircleBR,CircleBL;
  569.   int LTryUUR,LTryURR,LTryUUL,LTryULL;
  570.   int LTryBBR,LTryBRR,LTryBBL,LTryBLL;
  571.  
  572.   SquareUL=(Bitmap[X-1][Y] || Bitmap[X-1][Y+1] || Bitmap[X][Y+1]);
  573.   SquareUR=(Bitmap[X+1][Y] || Bitmap[X+1][Y+1] || Bitmap[X][Y+1]);
  574.   SquareBL=(Bitmap[X-1][Y] || Bitmap[X-1][Y-1] || Bitmap[X][Y-1]);
  575.   SquareBR=(Bitmap[X+1][Y] || Bitmap[X+1][Y-1] || Bitmap[X][Y-1]);
  576.   CircleUL=(!Bitmap[X-1][Y-1] && !Bitmap[X-1][Y] && !Bitmap[X-1][Y+1] &&
  577.             !Bitmap[X][Y+1] && !Bitmap[X+1][Y+1]);
  578.   CircleUR=(!Bitmap[X+1][Y-1] && !Bitmap[X+1][Y] && !Bitmap[X+1][Y+1] &&
  579.             !Bitmap[X][Y+1] && !Bitmap[X-1][Y+1]);
  580.   CircleBL=(!Bitmap[X-1][Y+1] && !Bitmap[X-1][Y] && !Bitmap[X-1][Y-1] &&
  581.             !Bitmap[X][Y-1] && !Bitmap[X+1][Y-1]);
  582.   CircleBR=(!Bitmap[X+1][Y+1] && !Bitmap[X+1][Y] && !Bitmap[X+1][Y-1] &&
  583.             !Bitmap[X][Y-1] && !Bitmap[X-1][Y-1]);
  584.   LTryUUL=(Bitmap[X-1][Y-1] && !Bitmap[X-1][Y] && !Bitmap[X-1][Y+1] &&
  585.            !Bitmap[X][Y+1] && !Bitmap[X+1][Y+1] && Bitmap[X+1][Y]);
  586.   LTryUUR=(Bitmap[X+1][Y-1] && !Bitmap[X+1][Y] && !Bitmap[X+1][Y+1] &&
  587.            !Bitmap[X][Y+1] && !Bitmap[X-1][Y+1] && Bitmap[X-1][Y]);
  588.   LTryBBL=(Bitmap[X-1][Y+1] && !Bitmap[X-1][Y] && !Bitmap[X-1][Y-1] &&
  589.            !Bitmap[X][Y-1] && !Bitmap[X+1][Y-1] && Bitmap[X+1][Y]);
  590.   LTryBBR=(Bitmap[X+1][Y+1] && !Bitmap[X+1][Y] && !Bitmap[X+1][Y-1] &&
  591.            !Bitmap[X][Y-1] && !Bitmap[X-1][Y-1] && Bitmap[X-1][Y]);
  592.   LTryULL=(!Bitmap[X-1][Y-1] && !Bitmap[X-1][Y] && !Bitmap[X-1][Y+1] &&
  593.            !Bitmap[X][Y+1] && Bitmap[X+1][Y+1] && Bitmap[X][Y-1]);
  594.   LTryURR=(!Bitmap[X+1][Y-1] && !Bitmap[X+1][Y] && !Bitmap[X+1][Y+1] &&
  595.            !Bitmap[X][Y+1] && Bitmap[X-1][Y+1] && Bitmap[X][Y-1]);
  596.   LTryBLL=(!Bitmap[X-1][Y+1] && !Bitmap[X-1][Y] && !Bitmap[X-1][Y-1] &&
  597.            !Bitmap[X][Y-1] && Bitmap[X+1][Y-1] && Bitmap[X][Y+1]);
  598.   LTryBRR=(!Bitmap[X+1][Y+1] && !Bitmap[X+1][Y] && !Bitmap[X+1][Y-1] &&
  599.            !Bitmap[X][Y-1] && Bitmap[X-1][Y-1] && Bitmap[X][Y+1]);
  600.   if (LTryUUL) fprintf(OutFile,"tuul(%d,%4.2f);",XX,YY);
  601.   if (LTryULL) fprintf(OutFile,"tull(%d,%4.2f);",XX,YY);
  602.   if (LTryUUR) fprintf(OutFile,"tuur(%d,%4.2f);",XX,YY);
  603.   if (LTryURR) fprintf(OutFile,"turr(%d,%4.2f);",XX,YY);
  604.   if (LTryBBL) fprintf(OutFile,"tbbl(%d,%4.2f);",XX,YY);
  605.   if (LTryBLL) fprintf(OutFile,"tbll(%d,%4.2f);",XX,YY);
  606.   if (LTryBBR) fprintf(OutFile,"tbbr(%d,%4.2f);",XX,YY);
  607.   if (LTryBRR) fprintf(OutFile,"tbrr(%d,%4.2f);",XX,YY);
  608.   if (SquareUL && SquareUR && SquareBL && SquareBR)
  609.     fprintf(OutFile,"s(%d,%4.2f);",XX,YY);
  610.   else
  611.     if (CircleUL && CircleUR && CircleBL && CircleBR)
  612.       fprintf(OutFile,"c(%d,%4.2f);",XX,YY);
  613.     else {
  614.       if (!LTryUUL && !LTryULL && !LTryUUR && !LTryBLL) 
  615.         if (SquareUL) fprintf(OutFile,"sul(%d,%4.2f);",XX,YY);
  616.         else
  617.           if (CircleUL) fprintf(OutFile,"cul(%d,%4.2f);",XX,YY);
  618.           else fprintf(OutFile,"tul(%d,%4.2f);",XX,YY);
  619.       if (!LTryUUL && !LTryURR && !LTryUUR && !LTryBRR)
  620.         if (SquareUR) fprintf(OutFile,"sur(%d,%4.2f);",XX,YY);
  621.         else
  622.           if (CircleUR) fprintf(OutFile,"cur(%d,%4.2f);",XX,YY);
  623.           else fprintf(OutFile,"tur(%d,%4.2f);",XX,YY);
  624.       if (!LTryBBL && !LTryULL && !LTryBBR && !LTryBLL)
  625.         if (SquareBL) fprintf(OutFile,"sbl(%d,%4.2f);",XX,YY);
  626.         else
  627.           if (CircleBL) fprintf(OutFile,"cbl(%d,%4.2f);",XX,YY);
  628.           else fprintf(OutFile,"tbl(%d,%4.2f);",XX,YY);
  629.       if (!LTryBBL && !LTryURR && !LTryBBR && !LTryBRR) 
  630.         if (SquareBR) fprintf(OutFile,"sbr(%d,%4.2f);",XX,YY);
  631.         else
  632.           if (CircleBR) fprintf(OutFile,"cbr(%d,%4.2f);",XX,YY);
  633.           else fprintf(OutFile,"tbr(%d,%4.2f);",XX,YY);
  634.     }
  635.   if (ferror(OutFile)) exit(1);
  636. }
  637.  
  638. void InactiveBitmap(FILE *OutFile, BitmapType Bitmap, int X, int Y, int XX, 
  639.                     float YY, int *Active)
  640. /* Writes METAFONT code for an inactive cell */
  641. /* Co-author is Mr. Masatoshi Watanabe */
  642. {
  643.   if (Bitmap[X-1][Y] && Bitmap[X][Y+1])
  644.     if (Bitmap[X-1][Y-1] && !Bitmap[X+1][Y+1])
  645.       { *Active=True; fprintf(OutFile,"ruul(%d,%4.2f);",XX,YY); }
  646.     else
  647.       if (Bitmap[X+1][Y+1] && !Bitmap[X-1][Y-1])
  648.         { *Active=True; fprintf(OutFile,"rull(%d,%4.2f);",XX,YY); }
  649.       else
  650.         { *Active=True; fprintf(OutFile,"rul(%d,%4.2f);",XX,YY); }
  651.   if (Bitmap[X+1][Y] && Bitmap[X][Y+1])
  652.     if (Bitmap[X+1][Y-1] && !Bitmap[X-1][Y+1])
  653.       { *Active=True; fprintf(OutFile,"ruur(%d,%4.2f);",XX,YY); }
  654.     else
  655.       if (Bitmap[X-1][Y+1] && !Bitmap[X+1][Y-1])
  656.         { *Active=True; fprintf(OutFile,"rurr(%d,%4.2f);",XX,YY); }
  657.       else
  658.         { *Active=True; fprintf(OutFile,"rur(%d,%4.2f);",XX,YY); }
  659.   if (Bitmap[X-1][Y] && Bitmap[X][Y-1])
  660.     if (Bitmap[X-1][Y+1] && !Bitmap[X+1][Y-1])
  661.       { *Active=True; fprintf(OutFile,"rbbl(%d,%4.2f);",XX,YY); }
  662.     else
  663.       if (Bitmap[X+1][Y-1] && !Bitmap[X-1][Y+1])
  664.         { *Active=True; fprintf(OutFile,"rbll(%d,%4.2f);",XX,YY); }
  665.       else
  666.         { *Active=True; fprintf(OutFile,"rbl(%d,%4.2f);",XX,YY); }
  667.   if (Bitmap[X+1][Y] && Bitmap[X][Y-1])
  668.     if (Bitmap[X+1][Y+1] && !Bitmap[X-1][Y-1])
  669.       { *Active=True; fprintf(OutFile,"rbbr(%d,%4.2f);",XX,YY); }
  670.     else
  671.       if (Bitmap[X-1][Y-1] && !Bitmap[X+1][Y+1])
  672.         { *Active=True; fprintf(OutFile,"rbrr(%d,%4.2f);",XX,YY); }
  673.       else
  674.         { *Active=True; fprintf(OutFile,"rbr(%d,%4.2f);",XX,YY); }
  675.   if (ferror(OutFile)) exit(1);
  676. }
  677.  
  678. void MiddleOut(FILE *OutFile, struct BitmapsType *Bitmaps, int Number, 
  679.                int Standard)
  680. /* Writes METAFONT code for a given Bitmap */
  681. {
  682.   int X,Y;
  683.   int Active;
  684.  
  685.   fprintf(OutFile,"beginchar(%d,%du#,",Number,Bitmaps->XMax-Bitmaps->XMin+1);
  686.   if (Standard) {
  687.     if (Bitmaps->YMax>0.75) fprintf(OutFile,"%4.2fu#,",Bitmaps->YMax-0.75);
  688.     else fprintf(OutFile,"0,");
  689.     if (5.75>Bitmaps->YMin) fprintf(OutFile,"%4.2fu#);\n",5.75-Bitmaps->YMin);
  690.     else fprintf(OutFile,"0);\n");
  691.   }
  692.   else {
  693.     if (Bitmaps->YMax>3) fprintf(OutFile,"%du#,",Bitmaps->YMax-3);
  694.     else fprintf(OutFile,"0,");
  695.     if (8>Bitmaps->YMin) fprintf(OutFile,"%du#);\n",8-Bitmaps->YMin);
  696.     else fprintf(OutFile,"0);\n");
  697.   }
  698.   fprintf(OutFile,"normal_adjust_fit(2u#,2u#);\n");
  699.   for (X=Bitmaps->XMin ; X<=Bitmaps->XMax ; X++)
  700.     for (Y=1 ; Y<=SizeMax ; Y++) {
  701.       Active=Bitmaps->Bitmap[X][Y];
  702.       if (Active)
  703.         /* Current pixel is on */
  704.         if (Standard) 
  705.           ActiveBitmap(OutFile,Bitmaps->Bitmap,X,Y,X-Bitmaps->XMin,Y-3.75);
  706.         else 
  707.           ActiveBitmap(OutFile,Bitmaps->Bitmap,X,Y,X-Bitmaps->XMin,Y-6);
  708.       else
  709.         /* Current pixel is off */
  710.         if (Standard) 
  711.           InactiveBitmap(OutFile,Bitmaps->Bitmap,X,Y,X-Bitmaps->XMin,Y-3.75,
  712.                          &Active);
  713.         else 
  714.           InactiveBitmap(OutFile,Bitmaps->Bitmap,X,Y,X-Bitmaps->XMin,Y-6,
  715.                          &Active);
  716.       /* Avoid METAFONT buffer overflow */
  717.       if (Active) fprintf(OutFile,"\n");
  718.   }
  719.   fprintf(OutFile,"endchar;\n");
  720.   fprintf(OutFile,"\n");
  721.   if (ferror(OutFile)) exit(1);
  722.  
  723. void EndOut(FILE *OutFile, struct RunTimeType *RunTime)
  724. /* Writes final METAFONT header */
  725. {
  726.   fprintf(OutFile,"font_identifier \"%s\";\n",RunTime->FileName);
  727.   if (RunTime->Standard) 
  728.     fprintf(OutFile,"font_coding_scheme \"JemTeX Standard\";\n");
  729.   else 
  730.     fprintf(OutFile,"font_coding_scheme \"JemTeX Dictionary\";\n");
  731.   fprintf(OutFile,"font_slant slant;\n");
  732.   fprintf(OutFile,"font_normal_space 8u#;\n");
  733.   fprintf(OutFile,"font_normal_stretch 4u#;\n");
  734.   fprintf(OutFile,"font_normal_shrink 3u#;\n");
  735.   fprintf(OutFile,"font_x_height 24u#; %%ex\n");
  736.   fprintf(OutFile,"font_quad 24u#; %%em\n");
  737.   fprintf(OutFile,"font_extra_space 0u#;\n");
  738.   fprintf(OutFile,"\n");
  739.   /* Must end with CR/LF because of a bug(?) in emTeX METAFONT */
  740.   fprintf(OutFile,"bye\n");
  741.   if (ferror(OutFile)) exit(1);
  742. }
  743.  
  744. /*--------------------------------- Generate --------------------------------*/
  745.  
  746. void FindWantedBitmap(int Automatic, int *First, int *WantedBitmap, int *Number)
  747. /* Finds number of the next desired Bitmap either automatically or manually */
  748. /* The characters 0 and 1 in the first font kanjiaa are both set to Bitmap 1 */
  749. {
  750.   int Valid;
  751.   AnswerType Answer;
  752.  
  753.   if (Automatic)
  754.     /* Find automatically */
  755.     if (*First)
  756.       /* Early in font kanjiaa */
  757.       if (*WantedBitmap==-1) *WantedBitmap=1;
  758.       else {
  759.         *WantedBitmap=1;
  760.         *First=False;
  761.       }
  762.     else
  763.       if ( (*Number==128) || (*WantedBitmap==BitmapMax) ) *WantedBitmap=0;
  764.       else (*WantedBitmap)++;
  765.   else
  766.     /* Find manually */
  767.     do {
  768.       printf("Bitmap number? ");
  769.       if (ferror(stdout)) exit(1);
  770.       if (gets(Answer)==NULL) exit(1);
  771.       if (1!=sscanf(Answer,"%d",WantedBitmap)) exit(1);
  772.       Valid=( (0<=*WantedBitmap) && (*WantedBitmap<=BitmapMax) );
  773.       if (!Valid) {
  774.         printf("\7Bitmap %d out of range...\n",*WantedBitmap);
  775.         if (ferror(stdout)) exit(1);
  776.       }
  777.     } while (!Valid);
  778.   printf("Bitmap number %d.\n",*WantedBitmap);
  779.   if (ferror(stdout)) exit(1);
  780. }
  781.  
  782. void ScanBitmap(FILE *InFile, BitmapType Bitmap, int *Empty)
  783. /* Reads the Bitmap in a logical grid */
  784. /* (0,0) is the lower left corner of the Bitmap */
  785. {
  786.   int Y;
  787.   BufferType Buffer;
  788.   struct ColumnType *Column;
  789.  
  790.   /* Read the Bitmap */
  791.   if (fread(Buffer,(unsigned)RecSize,1U,InFile)!=1U) exit(1);
  792.   /* Find if the Bitmap is empty */
  793.   *Empty=True;
  794.   for (Y=1 ; Y<=SizeMax ; Y++) {
  795.     Column=&Buffer[Y-1];
  796.     if ( (Column->Data1!=(unsigned char)'\x00') || 
  797.          (Column->Data2!=(unsigned char)'\x00') ||
  798.          (Column->Data3!=(unsigned char)'\x00') ) {
  799.       *Empty=False;
  800.       break;
  801.     }
  802.   }
  803.   /* Update logical grid */
  804.   if (!*Empty)
  805.     for (Y=1 ; Y<=SizeMax ; Y++) {            
  806.       Column=&Buffer[SizeMax-Y];
  807.       Bitmap[ 1][Y]=(int)(Column->Data1 & (unsigned char)'\x80');
  808.       Bitmap[ 2][Y]=(int)(Column->Data1 & (unsigned char)'\x40');
  809.       Bitmap[ 3][Y]=(int)(Column->Data1 & (unsigned char)'\x20');
  810.       Bitmap[ 4][Y]=(int)(Column->Data1 & (unsigned char)'\x10');
  811.       Bitmap[ 5][Y]=(int)(Column->Data1 & (unsigned char)'\x08');
  812.       Bitmap[ 6][Y]=(int)(Column->Data1 & (unsigned char)'\x04');
  813.       Bitmap[ 7][Y]=(int)(Column->Data1 & (unsigned char)'\x02');
  814.       Bitmap[ 8][Y]=(int)(Column->Data1 & (unsigned char)'\x01');
  815.       Bitmap[ 9][Y]=(int)(Column->Data2 & (unsigned char)'\x80');
  816.       Bitmap[10][Y]=(int)(Column->Data2 & (unsigned char)'\x40');
  817.       Bitmap[11][Y]=(int)(Column->Data2 & (unsigned char)'\x20');
  818.       Bitmap[12][Y]=(int)(Column->Data2 & (unsigned char)'\x10');
  819.       Bitmap[13][Y]=(int)(Column->Data2 & (unsigned char)'\x08');
  820.       Bitmap[14][Y]=(int)(Column->Data2 & (unsigned char)'\x04');
  821.       Bitmap[15][Y]=(int)(Column->Data2 & (unsigned char)'\x02');
  822.       Bitmap[16][Y]=(int)(Column->Data2 & (unsigned char)'\x01');
  823.       Bitmap[17][Y]=(int)(Column->Data3 & (unsigned char)'\x80');
  824.       Bitmap[18][Y]=(int)(Column->Data3 & (unsigned char)'\x40');
  825.       Bitmap[19][Y]=(int)(Column->Data3 & (unsigned char)'\x20');
  826.       Bitmap[20][Y]=(int)(Column->Data3 & (unsigned char)'\x10');
  827.       Bitmap[21][Y]=(int)(Column->Data3 & (unsigned char)'\x08');
  828.       Bitmap[22][Y]=(int)(Column->Data3 & (unsigned char)'\x04');
  829.       Bitmap[23][Y]=(int)(Column->Data3 & (unsigned char)'\x02');
  830.       Bitmap[24][Y]=(int)(Column->Data3 & (unsigned char)'\x01');
  831.   }
  832. }
  833.  
  834. void ScanSides(struct BitmapsType *Bitmaps, int FixedX, int FixedY)
  835. /* Determines the minimal size of the Bitmap for proportional spacing */
  836. {
  837.   int X,Y;
  838.  
  839.   if (FixedX) { 
  840.     Bitmaps->XMin=1; 
  841.     Bitmaps->XMax=SizeMax; 
  842.   }
  843.   else {
  844.     Bitmaps->XMin=SizeMax1;
  845.     for (X=SizeMax ; X>=1 ; X--)
  846.       for (Y=1 ; Y<=SizeMax ; Y++)
  847.         if (Bitmaps->Bitmap[X][Y]) Bitmaps->XMin=X;
  848.     Bitmaps->XMax=0;
  849.     for (X=1 ; X<=SizeMax ; X++)
  850.       for (Y=1 ; Y<=SizeMax ; Y++)
  851.         if (Bitmaps->Bitmap[X][Y]) Bitmaps->XMax=X;
  852.   }
  853.   if (FixedY) {
  854.     Bitmaps->YMin=1; 
  855.     Bitmaps->YMax=SizeMax; 
  856.   }
  857.   else {
  858.     Bitmaps->YMin=SizeMax1;
  859.     for (Y=SizeMax ; Y>=1 ; Y--)
  860.       for (X=1 ; X<=SizeMax ; X++)
  861.         if (Bitmaps->Bitmap[X][Y]) Bitmaps->YMin=Y;
  862.     Bitmaps->YMax=0;
  863.     for (Y=1 ; Y<=SizeMax ; Y++)
  864.       for (X=1 ; X<=SizeMax ; X++)
  865.         if (Bitmaps->Bitmap[X][Y]) Bitmaps->YMax=Y;
  866.   }
  867. }
  868.  
  869. void Generate(FILE *InFile, FILE *OutFile, int *Number, 
  870.               struct RunTimeType *RunTime)
  871. /* Generates the METAFONT code for the selected font */
  872. {
  873.   /* Bitmap pointers */
  874.   int CurrentBitmap,WantedBitmap;
  875.   /* Current Bitmap and its dimensions */
  876.   struct BitmapsType Bitmaps;
  877.   int X,Y;
  878.   /* Indicates early in font kanjiaa */
  879.   int First;
  880.   /* Indicates current Bitmap is empty */
  881.   int Empty;
  882.  
  883.   /* Clear the area outside the Bitmap once and for all */
  884.   for (X=0 ; X<=SizeMax1 ; X++) {
  885.     Bitmaps.Bitmap[X][0]=False; Bitmaps.Bitmap[X][SizeMax1]=False; }
  886.   for (Y=1 ; Y<=SizeMax ; Y++) {
  887.     Bitmaps.Bitmap[0][Y]=False; Bitmaps.Bitmap[SizeMax1][Y]=False; }
  888.   /* Number of the Bitmap ready to be read */
  889.   CurrentBitmap=1;
  890.   /* First METAFONT character number */
  891.   *Number=0;
  892.   /* First Bitmap wanted */
  893.   if (RunTime->Automatic) {
  894.     WantedBitmap=1024 * ( toupper(RunTime->FileName[5])-'A' ) +
  895.                  128 * ( toupper(RunTime->FileName[6])-'A' ) - 1;
  896.     First=(WantedBitmap==-1);
  897.   }
  898.   do {
  899.     FindWantedBitmap(RunTime->Automatic,&First,&WantedBitmap,Number);
  900.     if (WantedBitmap) {
  901.       /* Position pointer */
  902.       if (WantedBitmap!=CurrentBitmap) {
  903.         if ( fseek(InFile , ((WantedBitmap-1L)*RecSize) , 0) ) exit(1);
  904.         CurrentBitmap=WantedBitmap;
  905.       }
  906.       printf("Reading Bitmap");
  907.       if (ferror(stdout)) exit(1);
  908.       ScanBitmap(InFile,Bitmaps.Bitmap,&Empty);
  909.       CurrentBitmap++;
  910.       printf(".\n");
  911.       if (ferror(stdout)) exit(1);
  912.       /* Process Bitmap */
  913.       if (Empty) printf("Bitmap is empty, no METAFONT code %d.\n",*Number);
  914.       else {
  915.         printf("Writing METAFONT code %d",*Number);
  916.         ScanSides(&Bitmaps,RunTime->FixedX,RunTime->FixedY);
  917.         MiddleOut(OutFile,&Bitmaps,*Number,RunTime->Standard);
  918.         printf(".\n");
  919.       }
  920.       printf("\n");
  921.       if (ferror(stdout)) exit(1);
  922.       /* Ready to generate next METAFONT character */
  923.       (*Number)++;
  924.     }
  925.   } while (WantedBitmap);
  926. }
  927.  
  928. /*----------------------------------- Main ----------------------------------*/
  929.  
  930. main(int argc, char *argv[])
  931. {
  932.   /* JIS24 and METAFONT file names */
  933.   FILE *InFile;
  934.   FILE *OutFile;
  935.   TotalNameType TotalName;
  936.   /* Current METAFONT character number */
  937.   int Number;
  938.   /* Run time parameters */
  939.   struct RunTimeType RunTime;
  940.  
  941.   printf("\n");
  942.   printf("Bitmaps to METAFONT Conversion Program.\n");  /*To make Borland happy*/
  943.   printf("Version 2.00 Copyright F. Jalbert 1991.\n");
  944.   printf("\n");
  945.   if (ferror(stdout)) exit(1);
  946.  
  947.   printf("Opening Bitmap file JIS24");
  948.   InFile=fopen("jis24","rb");
  949.   if (InFile==NULL) exit(1);
  950.   printf(".\n");
  951.   printf("\n");
  952.   if (ferror(stdout)) exit(1);
  953.  
  954.   GetParameters(&RunTime,argc,argv);
  955.   strcpy(TotalName,RunTime.FileName);
  956.   strcat(TotalName,".mf");
  957.   printf("Creating METAFONT file %s",TotalName);
  958.   OutFile=fopen(TotalName,"wt");
  959.   if (OutFile==NULL) exit(1);
  960.   printf(".\n");
  961.   printf("\n");
  962.   if (ferror(stdout)) exit(1);
  963.  
  964.   printf("Writing initial METAFONT header");
  965.   #ifndef __TURBOC__
  966.   printf("\n");
  967.   #endif
  968.   BeginOut(OutFile,&RunTime);
  969.   printf(".\n");
  970.   printf("\n");
  971.   Generate(InFile,OutFile,&Number,&RunTime);
  972.   printf("\n");
  973.   if (ferror(stdout)) exit(1);
  974.  
  975.   printf("Writing final METAFONT header");
  976.   #ifndef __TURBOC__
  977.   printf("\n");
  978.   #endif
  979.   EndOut(OutFile,&RunTime);
  980.   printf(".\n");
  981.   printf("Closing METAFONT file %s",TotalName);
  982.   if (fclose(OutFile)==EOF) exit(1);
  983.   printf(".\n");
  984.   printf("Closing Bitmap file JIS24");
  985.   if (fclose(InFile)==EOF) exit(1);
  986.   printf(".\n");
  987.   printf("\n");
  988.   if (ferror(stdout)) exit(1);
  989.  
  990.   printf("METAFONT code for %d Bitmap(s) generated.\n",Number);
  991.   printf("\n");
  992.   if (ferror(stdout)) exit(1);
  993.  
  994.   return(0);
  995. }
  996.